<template>
	<section>
		<full-screen-dialog :title="titleMap[mode]" v-model="visible" :width="1200" destroy-on-close @closed="$emit('closed')">
			<el-form :disabled="mode == 'Show'" ref="dialogForm" label-width="100px">
				<el-descriptions :column="4">
					<el-descriptions-item label="销售单日期">{{entityObj.orderTime}}</el-descriptions-item>
					<el-descriptions-item label="销售单编号">{{entityObj.orderCode}}</el-descriptions-item>
					<el-descriptions-item label="客户">{{entityObj.storeFullName}}</el-descriptions-item>
					<el-descriptions-item label="业务员">{{entityObj.salesman || '无'}}</el-descriptions-item>
					<el-descriptions-item label="制单人">{{entityObj.documentsUser}}</el-descriptions-item>
					<el-descriptions-item label="关联要货单">{{entityObj.applyOrderCode}}</el-descriptions-item>
				</el-descriptions>
				<el-table :data="entityObj.checkItems" :border="true" style="width: 100%" show-summary>
					<el-table-column label="物料编码" prop="materialCode"></el-table-column>
					<el-table-column label="物料名称" prop="materialName"></el-table-column>
					<el-table-column label="规格型号" prop="materialSpecs"></el-table-column>
					<el-table-column label="供应商" width="200" prop="supplierName"></el-table-column>
					<el-table-column prop="qty" label="数量">
						<template #default="scope">
							<el-input-number v-model="scope.row.qty" style="width: 100%" :step="1"
								controls-position="right"></el-input-number>
						</template>
					</el-table-column>
					<el-table-column label="结算价">
						<template #default="scope">
							<el-input-number v-model="scope.row.price" style="width: 100%" :step="1"
								controls-position="right"></el-input-number>
						</template>
					</el-table-column>
					<el-table-column label="单位" prop="unitName"></el-table-column>
					<el-table-column label="价税合计" prop="unitName"></el-table-column>
					<el-table-column label="备注">
						<template #default="scope">
							<el-input v-model="scope.row.remarks" />
						</template>
					</el-table-column>
				</el-table>
			</el-form>

			<template #footer>
				<div style="text-align: center;">
					<el-button @click="visible = false">关 闭</el-button>
					<!-- <el-button type="primary"  @click="submit()">预览单据</el-button>
					<el-button type="primary" v-if="mode != 'Show'" @click="submit()">打印单据</el-button> -->
					<el-button type="primary" v-if="mode != 'Show'" @click="submit()">保存</el-button>
				</div>
			</template>
		</full-screen-dialog>
	</section>
</template>

<script>
	import tool from "@/utils/tool";
	export default {
		emits: ["success", "closed"],
		data() {
			return {
				mode: "Check",
				titleMap: {
					Check: "销售单核对",
					Show: "物料明细",
				},
				visible: false,
				entityObj: {
					orderCode: '',
					orderTime: '',
					salesman: '',
					documentsUser: '',
					signUser: '',
					applyOrderCode: '',
					storeName: '',
					receivingOrderItems: []
				},
				rules: {},

			}
		},
		methods: {
			//显示=
			open(mode = "Check") {
				
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单注入数据
			async setData(data) {
				console.log('data1:', data)
				try {
					this.entityObj = structuredClone(data); 
					this.entityObj.checkItems = [];
					this.entityObj.checkItems.push(this.entityObj);

					// var obj= data.orderCodeItems.find(item=>{
					// 	return data.receivingOrderId=item.receivingOrderId
					// })
					// if(obj!=undefined){
					// 	this.entityObj.orderCodeItems=[];
					// 	this.entityObj.orderCodeItems.push(obj);
					// }else{
					// 	this.entityObj.orderCodeItems=[];
					// }
					// var returnValue = await this.$API.auth.PostProcessApi.post(
					//     "purchase-order/send-detail",
					//     { purchaseOrderIds: data }
					// );
					// if (returnValue.status == 200) {
					//     this.entityObj = { ...returnValue.response, logisticsId: null, logisticsCode: "", sendDate: tool.formatDate(new Date()) };
					//     this.queryList = {};
					//     this.handleSearch();
					// } else {
					//     this.$message.error("操作失败:" + returnValue.msg);
					// }
				} catch (error) {
					this.loading = false;
					return false;
				}
			},
			async submit() {
				// console.log(this.entityObj.checkItems[0])
				let sendModal = {
					qty: this.entityObj.checkItems[0].qty,
					price: this.entityObj.checkItems[0].price,
					remarks: this.entityObj.checkItems[0].remarks,
					receivingOrderId: this.entityObj.checkItems[0].receivingOrderId
				}
				const returnValue = await this.$API.auth.PostProcessApi.post(
					"receiving-order/check",
					sendModal
				);
				if (returnValue.status == 200) {
					this.$message.success(returnValue.msg);
					this.$emit("fatherMethod",sendModal);
					this.visible = false;
				} else {
					this.$message.error("操作失败:" + returnValue.msg);
				}
			}
		}
	}
</script>

<style scoped>
</style>
